home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
m2
/
cat3src
/
putz
/
putzlist.i
< prev
next >
Wrap
Text File
|
1997-10-26
|
13KB
|
435 lines
IMPLEMENTATION MODULE PutzList;
FROM SYSTEM IMPORT ADDRESS, ADR, CADR, TSIZE, BYTE, ASSEMBLER, CALLSYS;
IMPORT Strings;
FROM StrConv IMPORT LNumToStr, NumToStr, StrToCard, CardToStr,
StrToLInt;
IMPORT MagicStrings;
(* CATPUTZ-Module *)
FROM PutzTypes IMPORT grListEntry, ptrGrEntry, defaultOpts, delState,
totalEntry, putzList, TextJustification,
ptrDispEntry, listEntryType, MaxStr;
(* CAT-Module *)
IMPORT ConfVars;
FROM Void IMPORT v;
CONST
maxParts = 20; (* Anzahl der maximalen verschiedenen Zeilenteile *)
partFormatLength = 32; (* maximale Lnge eines Formatstrings *)
CONST
cTotal = "Gesamt";
cName = "Gruppe";
cKaputt1 = "Kaputt";
cKaputt2 = "# (%)";
cTotalDel1 = "Total";
cTotalDel2 = "# (%)";
cPartDel1 = "Teil";
cPartDel2 = "# (%)";
cPreMsg1 = "Messages";
cPreMsg2 = "vorher";
cPostMsg1 = "Messages";
cPostMsg2 = "nachher";
cPreBytes1 = "Gre";
cPreBytes2 = "vorher";
cPostBytes1 = "Gre";
cPostBytes2 = "nachher";
cDelBytes1 = "Bytes";
cDelBytes2 = "gelscht";
cFormatLine = "DisplayFormat";
TYPE
partNameType = (pGroup, pBadDel, pTotalDel, pPartDel,
pPreMsgs, pPostMsgs, pPreBytes, pPostBytes,
pDelBytes);
partFormat = ARRAY [0..partFormatLength-1] OF CHAR;
partType = RECORD
type : partNameType;
w : INTEGER;
formatStr : partFormat;
END;
partArrayType = ARRAY [0..maxParts-1] OF partType;
partArrayDesc = RECORD
lines : INTEGER;
width : INTEGER;
maxNameWidth : INTEGER;
parts : partArrayType;
END;
VAR listParts : partArrayDesc;
PROCEDURE GetPartCount(): INTEGER;
BEGIN
RETURN listParts.lines-1;
END GetPartCount;
PROCEDURE GetMaxLineWidth(): INTEGER;
VAR width : INTEGER;
i : INTEGER;
BEGIN
width := 0;
FOR i := 0 TO listParts.lines-1 DO
INC (width, GetPartWidth (i));
END;
RETURN width;
END GetMaxLineWidth;
PROCEDURE GetPartWidth (part: INTEGER): INTEGER;
BEGIN
IF (listParts.parts[part].type = pGroup)
& (listParts.parts[part].w = -1)
THEN
(* Maximale Lnge eines Gruppennamens zurckgeben *)
RETURN listParts.maxNameWidth;
END;
RETURN listParts.parts[part].w;
END GetPartWidth;
PROCEDURE GetPartType (part: INTEGER): partNameType;
BEGIN
RETURN listParts.parts[part].type;
END GetPartType;
PROCEDURE ExtendStr (VAR str : ARRAY OF CHAR; l : CARDINAL; just: TextJustification);
VAR (*$Reg *) c : CARDINAL;
f1, f2: CARDINAL;
BEGIN
c := LENGTH (str);
IF c < l
THEN
IF just = justLeft
THEN
MagicStrings.Append (Strings.Space (l-c), str);
ELSIF just = justCenter
THEN
f1 := (l - c) DIV 2;
f2 := (l - c) - f1;
MagicStrings.Insert (Strings.Space (f1), str, 0);
MagicStrings.Append (Strings.Space (f2), str);
ELSE
MagicStrings.Insert (Strings.Space (l-c), str, 0);
END;
END;
END ExtendStr;
PROCEDURE CalcPercent (org, remain : LONGCARD) : LONGCARD;
VAR fOrg, fRem, tmp,
percent : LONGREAL;
BEGIN
IF (org = 0) OR (remain = 0) THEN RETURN 0 END;
fOrg := LFLOAT (org);
fRem := LFLOAT (remain);
percent := 100.0 / (fOrg / fRem);
RETURN TRUNC (percent)
END CalcPercent;
PROCEDURE CalcKiloBytes (theNumber : LONGCARD) : LONGCARD;
VAR kB : LONGCARD;
BEGIN
kB := theNumber DIV 1024L;
IF theNumber MOD 1024L # 0 THEN INC (kB) END;
RETURN kB
END CalcKiloBytes;
PROCEDURE FormatNumber (num1, num2: LONGCARD; width: CARDINAL;
VAR str: ARRAY OF CHAR);
VAR tmpStr : ARRAY [0..255] OF CHAR;
perStr : ARRAY [0..255] OF CHAR;
BEGIN
MagicStrings.Assign (CardToStr (num1, 0), tmpStr);
MagicStrings.Assign (" (", perStr);
MagicStrings.Append (CardToStr(CalcPercent (num2, num1), 2), perStr);
MagicStrings.Append ("%)", perStr);
MagicStrings.Assign (tmpStr, str);
IF LENGTH (tmpStr) + LENGTH (perStr) <= width
THEN
MagicStrings.Append (perStr, str);
END;
END FormatNumber;
PROCEDURE GetPartJustification (ptr: ptrDispEntry; part: INTEGER): TextJustification;
BEGIN
IF GetPartType (part) = pGroup
THEN
RETURN justLeft;
ELSE
IF ptr^.type = dataEntry
THEN
RETURN justRight;
ELSE
RETURN justCenter;
END;
END;
END GetPartJustification;
PROCEDURE GetPart (ptr: ptrDispEntry; part: INTEGER;
VAR str: ARRAY OF CHAR; fillUp: BOOLEAN);
VAR maxWidth : INTEGER;
tmpStr : ARRAY [0..255] OF CHAR;
dataPtr : ptrGrEntry;
just : TextJustification;
BEGIN
MagicStrings.Assign ("", str);
maxWidth := GetPartWidth (part);
dataPtr := ptr^.data;
CASE GetPartType (part) OF
pGroup :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cName, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
IF dataPtr^.info = NIL
THEN
MagicStrings.Copy (cTotal, 0, maxWidth, str);
ELSE
MagicStrings.Copy (dataPtr^.info^.name^, 0, maxWidth, str);
END;
END; |
pBadDel :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cKaputt1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cKaputt2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
FormatNumber (dataPtr^.badDel, dataPtr^.preMsgs, maxWidth, str);
END; |
pTotalDel :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cTotalDel1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cTotalDel2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
FormatNumber (dataPtr^.totalDel, dataPtr^.preMsgs, maxWidth, str);
END; |
pPartDel :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cPartDel1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cPartDel2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
FormatNumber (dataPtr^.partDel, dataPtr^.preMsgs, maxWidth, str);
END; |
pPreMsgs :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cPreMsg1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cPreMsg2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
MagicStrings.Assign (CardToStr (dataPtr^.preMsgs,0), str);
END; |
pPostMsgs :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cPostMsg1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cPostMsg2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
MagicStrings.Assign (CardToStr (dataPtr^.postMsgs,0), str);
END; |
pPreBytes :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cPreBytes1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cPreBytes2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
MagicStrings.Assign (CardToStr (CalcKiloBytes(dataPtr^.preBytes),0), str);
MagicStrings.Append (" KB", str);
END; |
pPostBytes :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cPostBytes1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cPostBytes2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
MagicStrings.Assign (CardToStr (CalcKiloBytes(dataPtr^.postBytes),0), str);
MagicStrings.Append (" KB", str);
END; |
pDelBytes :
IF ptr^.type = listHead1
THEN
MagicStrings.Copy (cDelBytes1, 0, maxWidth, str);
ELSIF ptr^.type = listHead2
THEN
MagicStrings.Copy (cDelBytes2, 0, maxWidth, str);
ELSIF ptr^.type = dataEntry
THEN
IF (dataPtr^.postBytes > 0) & (dataPtr^.preBytes >= dataPtr^.postBytes)
THEN
MagicStrings.Assign (CardToStr (CalcKiloBytes(dataPtr^.preBytes - dataPtr^.postBytes),0), str);
ELSE
MagicStrings.Assign ("0", str);
END;
MagicStrings.Append (" KB", str);
END; |
ELSE
END;
IF fillUp
THEN
ExtendStr (str, maxWidth, GetPartJustification (ptr, part))
END;
END GetPart;
PROCEDURE SetMaxNameLength (maxLen : INTEGER);
BEGIN
listParts.maxNameWidth := maxLen;
END SetMaxNameLength;
PROCEDURE parseFormatLine (REF listline : ARRAY OF CHAR; onlyTest : BOOLEAN) : BOOLEAN;
TYPE charSet = SET OF CHAR;
CONST okSet = charSet{'B','D', 'G', 'M', 'N', 'T', 'V', 'W', 'X'};
numSet = charSet{'-','0'..'9'};
skipSet = charSet{' ',','};
formatSet = charSet{};
VAR p : partArrayDesc;
num : LONGINT;
ch : CHAR;
z, l: CARDINAL;
pName : partNameType;
fStr : partFormat;
i : INTEGER;
negative: BOOLEAN;
pos : CARDINAL;
numStr: MaxStr;
BEGIN
l := LENGTH (listline);
IF l = 0 THEN RETURN FALSE END;
z := 0;
p.lines := 0;
p.width := 0;
WHILE z < l DO
(* Ersten Eintrag suchen *)
WHILE (z < l) & (listline[z] IN skipSet) DO INC (z) END;
IF z < l
THEN
ch := listline[z];
FOR i := 0 TO partFormatLength-1 DO fStr[i] := 0C; END;
IF (listline[z+1] # '(') THEN RETURN FALSE END;
INC (z,2); (* z+1 = '(' *)
num := 0;
i := 0;
WHILE (listline [z] IN numSet) & (z < l) DO
numStr[i] := listline[z];
INC (i);
(* num := num * 10 + LONG(ORD (listline[z]) - ORD('0')); *)
INC(z);
END;
numStr[i] := '';
pos := 0;
num := StrToLInt (numStr, pos, v.bool);
IF (z >= l) OR
( (listline[z] # ')') &
( (listline[z] # ',') & ~(ch IN formatSet))
)
THEN
RETURN FALSE
END;
IF (listline[z] = ',') & (ch IN formatSet)
THEN
(* Formatstring lesen *)
INC (z); (* ',' berspringen *)
i := 0;
WHILE (listline[z] # ')') & (z < l) & (i < partFormatLength) DO
fStr[i] := listline[z];
INC (z); INC (i);
END;
IF (i >= partFormatLength) OR (z >= l) THEN RETURN FALSE END;
END;
INC(z); (* ')' berspringen *)
CASE ch OF
'B' : pName := pBadDel; |
'D' : pName := pTotalDel; |
'G' : pName := pGroup; |
'M' : pName := pPreMsgs; |
'N' : pName := pPostMsgs; |
'T' : pName := pPartDel; |
'V' : pName := pPreBytes; |
'W' : pName := pPostBytes; |
'X' : pName := pDelBytes; |
ELSE
RETURN FALSE;
END;
IF (num = 0) OR (num > 1024) THEN RETURN FALSE END;
p.parts[p.lines] := partType{pName, INTEGER(SHORT(num)), fStr};
INC (p.lines);
INC (p.width, num);
END;
END;
IF p.lines = 0
THEN
RETURN FALSE
END;
IF onlyTest THEN RETURN TRUE END;
v.bool := ConfVars.SetConfigString (cFormatLine, listline);
listParts := p;
RETURN TRUE;
END parseFormatLine;
PROCEDURE ParseFormat (REF format: ARRAY OF CHAR);
BEGIN
v.bool := parseFormatLine (format, FALSE);
END ParseFormat;
PROCEDURE CheckFormatLine (REF listline : ARRAY OF CHAR): BOOLEAN;
(* Das Format einer Zeile besteht aus einzelnen Krzeln
* fr einen Eintrag und darauffolgend in Klammern die Weite dieses Eintrages.
* Beispiel: D(12),I(10),U(30),W(30),F(2)
* Erlaubte Zeilenelemente:
* G: Gruppe. Bei einer Weite von -1 wird die Lnge des lngsten Namens
* genommen
* B: Anzahl beschdigte Nachrichten
* D: Anzahl totalgelschter Nachrichten
* T: Anzahl teilgelschter Nachrichten
* M: Anzahl Nachrichten vorher
* N: Anzahl Nachrichten nachher
* V: Kilobytes vorher
* W: Kilobytes nachher
* X: Kilobytes gelscht
*)
BEGIN
RETURN parseFormatLine (listline, TRUE);
END CheckFormatLine;
PROCEDURE InitFormat();
VAR str : ARRAY [0..255] OF CHAR;
BEGIN
IF ~ConfVars.GetConfigString (cFormatLine, str)
THEN
MagicStrings.Assign ("G(-1),M(12),V(10),D(12),T(12),B(12),N(12),W(10),X(10)", str);
END;
ParseFormat (str);
END InitFormat;
END PutzList.